package com.gitee.feizns.quickstart.web.ex.impl;

import com.gitee.feizns.quickstart.domain.vo.Ret;
import com.gitee.feizns.quickstart.web.ex.BadRequestException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

/**
 * 请求参数错误的异常处理器
 * @author feizns
 * @since 2023/04/20
 */
public class BadRequestExceptionHandler extends AbstractExceptionHandler<BadRequestException> {

    /**
     * http状态
     */
    private final HttpStatus httpStatus;

    public BadRequestExceptionHandler(HttpStatus httpStatus) {
        this.httpStatus = httpStatus;
    }

    @Override
    public ResponseEntity<Ret<?>> handle(BadRequestException e) {
        return ResponseEntity.status(httpStatus)
                .body(Ret.error(HttpStatus.BAD_REQUEST.value(), e.getMessage()));
    }

}
